package Database;

import java.sql.*;
import java.util.ArrayList;

import Model.Year;

public class YearDB {

	public static ArrayList<Year> getAllYears()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM apptYear ORDER BY year";

		ArrayList<Year> yearArr = new ArrayList<Year>();
		Year year = null;

		try
		{
			stmt = con.prepareStatement(select);
			// stmt.setString(1, credID);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				year = new Year();
				year.setYear(rs.getString("year"));
				year.setYearsub(rs.getString("year_short"));
				yearArr.add(year);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			year = null;
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return yearArr;
	}
	
}
